<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 600px;
            height: 400px;
        }
    </style>
</head>

<body>
    <div id="app">
        <div>
            <p>
                名称：<input v-model="val" type="text">
            </p>
            <p>
                数量：<input v-model.number="num" type="text">
            </p>
            <button @click="push">提交</button>
        </div>

        <div class="box" ref="chat">

        </div>
    </div>

    <script src="./js/vue.js"></script>
    <script crossorigin="anonymous"
        integrity="sha512-RjdGUelydi9tlywPU+UXK4pTF9zeUAVxnMIvNgy5HJAzCLj/tllE0Z1UxxbemFknstsiKZZXlP/pedzZ86kvFw=="
        src="https://lib.baomitu.com/echarts/5.3.0/echarts.common.js"></script>

    <script>
        new Vue({
            el: "#app",
            data: {
                val: "",
                num: null,
                xAxisData: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子'],
                barData: [5, 20, 36, 10, 10, 20]
            },
            created() {
            },
            // mounted --  可以操作Dom结构
            mounted() {
                this.init()
            },
            methods: {
                push() {
                    this.xAxisData.push(this.val)
                    this.barData.push(this.num)
                    this.init()
                },
                init() {
                    var myChart = echarts.init(this.$refs.chat)
                    var option = {
                        title: {
                            text: 'ECharts 入门示例'
                        },
                        tooltip: {},
                        legend: {
                            data: ['销量']
                        },
                        xAxis: {
                            data: this.xAxisData
                        },
                        yAxis: {},
                        series: [
                            {
                                name: '销量',
                                type: 'bar',
                                data: this.barData
                            }
                        ]
                    };
                    myChart.setOption(option);
                }
            }
        })
    </script>
</body>

</html>